﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;

namespace WebServiceTool.Models
{
    /// <summary>
    /// WebService方法信息
    /// </summary>
    public class WebServiceOperation : INotifyPropertyChanged
    {
        #region 字段
        /// <summary>
        ///   服务方法名称
        /// </summary>
        private string _name;

        /// <summary>
        ///   服务方法描述
        /// </summary>
        private string _description;

        /// <summary>
        ///   输入参数列表
        /// </summary>
        private List<InputParameter> _inputParameters = new List<InputParameter>();

        private ICommand _invokeMethodCommand;
        #endregion

        #region 属性
        public string Name
        {
            get => _name;
            set
            {
                _name = value;
                OnPropertyChanged();
            }
        }

        public string Description
        {
            get => _description;
            set
            {
                _description = value;
                OnPropertyChanged();
            }
        }

        /// <summary>
        /// 输入参数列表
        /// </summary>
        public List<InputParameter> InputParameters
        {
            get => _inputParameters;
            set
            {
                _inputParameters = value;
                OnPropertyChanged();
            }
        }

        /// <summary>
        /// 调用方法命令
        /// </summary>
        public ICommand InvokeMethodCommand
        {
            get => _invokeMethodCommand;
            set
            {
                _invokeMethodCommand = value;
                OnPropertyChanged();
            }
        }
        #endregion

        #region 事件
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion

        #region INotifyPropertyChanged实现
        private void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
    
    /// <summary>
    /// 方法参数模型
    /// </summary>
    public class InputParameter : INotifyPropertyChanged
    {
        #region 字段
        private string _name;
        private string _type;
        private string _description;
        private object _value;
        #endregion

        #region 属性
        /// <summary>
        /// 参数名称
        /// </summary>
        public string Name
        {
            get => _name;
            set
            {
                _name = value;
                OnPropertyChanged();
            }
        }

        /// <summary>
        /// 参数类型
        /// </summary>
        public string Type
        {
            get => _type;
            set
            {
                _type = value;
                OnPropertyChanged();
            }
        }

        /// <summary>
        /// 参数描述
        /// </summary>
        public string Description
        {
            get => _description;
            set
            {
                _description = value;
                OnPropertyChanged();
            }
        }

        /// <summary>
        /// 参数值
        /// </summary>
        public object Value
        {
            get => _value;
            set
            {
                _value = value;
                OnPropertyChanged();
            }
        }

        /// <summary>
        /// 参数最小出现次数
        /// </summary>
        public int MinOccurs { get; set; }
        
        /// <summary>
        ///  参数最大出现次数
        /// </summary>
        public int MaxOccurs { get; set; }
        #endregion

        #region 事件
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion

        #region INotifyPropertyChanged实现
        private void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
}